package com.wzl.customviewproject.adapter;

import android.util.Log;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.Lifecycle;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import com.wzl.customviewproject.fragment.TestFragmentOne;
import com.wzl.customviewproject.fragment.TestFragmentSecond;
import com.wzl.customviewproject.fragment.TestFragmentThird;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者：longxiansen
 * 功能：
 */
public class XiaoMiFragmentsAdapter extends FragmentStateAdapter {
//    String[] tabs = new String[]{"推荐", "XiaoMi手机", "最新"};
    List<String> list = new ArrayList<>();

    public XiaoMiFragmentsAdapter(@NonNull @NotNull FragmentManager fragmentManager, @NonNull @NotNull Lifecycle lifecycle) {
        super(fragmentManager, lifecycle);
        list.add("推荐");
        list.add("XiaoMi手机");
        list.add("RedMi手机");
/*        list.add("游戏手机");
        list.add("电脑平板");
        list.add("智能穿戴");
        list.add("电视");
        list.add("大家电");
        list.add("小家电");
        list.add("智能家居");
        list.add("户外出行");
        list.add("日用百货");
        list.add("儿童用品");
        list.add("有品精选");
        list.add("小米服务");*/
    }

    @NonNull
    @NotNull
    @Override
    public Fragment createFragment(int position) {
        switch (position) {
            case 0:
            default:
                return TestFragmentOne.newInstance();
            case 1:
                return TestFragmentSecond.newInstance();
            case 2:
                return TestFragmentThird.newInstance();
        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    @Override
    public void onDetachedFromRecyclerView(@NonNull @NotNull RecyclerView recyclerView) {
        super.onDetachedFromRecyclerView(recyclerView);
        Log.d("testOne", "onDetachedFromRecyclerView: ");
    }

    @Override
    public void onAttachedToRecyclerView(@NonNull @NotNull RecyclerView recyclerView) {
        super.onAttachedToRecyclerView(recyclerView);
        Log.d("testOne", "onAttachedToRecyclerView: ");
    }

    @Override
    public boolean containsItem(long itemId) {
        Log.d("testOne", "containsItem: "+itemId);
        return super.containsItem(itemId);
    }


}
